<template>
  <div>
    <van-nav-bar title="编辑信息" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
      <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名" />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
      />
      <van-field
        v-model="phone"
        type="phone"
        name="手机号"
        label="手机号"
        placeholder="手机号"
      />
      <van-field
        v-model="gender"
        type="gender"
        name="性别"
        label="性别"
        placeholder="性别"
      />
      <van-field v-model="age" type="age" name="年龄" label="年龄" placeholder="年龄" />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import url from "../tools/url.js";
import { Toast } from "mint-ui";
export default {
  name: "BianJi",
  data() {
    return {
      id: "",
      username: "",
      password: "",
      phone: "",
      gender: "",
      age: "",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSubmit() {
      var token = sessionStorage.getItem("token");
      var str = `id=${this.id}&token=${token}$phone=${this.phone}&name=${this.username}&gender=${this.gender}&age=${this.age}&password=${this.password}`;
      this.axios.post(url.UPDATA, str).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          sessionStorage.setItem("token", res.data.data.token);
          this.$store.commit("save", res.data.data);
          this.$router.push("/WoDe");
        } else {
          Toast(res.data.message);
        }
      });
    },
  },
  mounted() {
    this.id = this.$route.query.id;
  },
};
</script>
<style scoped></style>
